package com.lagou.service.impl;

import com.lagou.dao.PromotionSpaceMapper;
import com.lagou.domain.PromotionSpace;
import com.lagou.service.PromotionSpaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class PromotionSpaceServiceImpl implements PromotionSpaceService {

    @Autowired
    private PromotionSpaceMapper promotionSpaceMapper;

    /*查询所有广告*/
    @Override
    public List<PromotionSpace> findAllPromotionSpace() {

        List<PromotionSpace> promotionSpaceList = promotionSpaceMapper.findAllPromotionSpace ();


        return promotionSpaceList;
    }

    /*新增广告位*/
    @Override
    public void savePromotionSpace(PromotionSpace promotionSpace) {

        //封装数据
        UUID uuid = UUID.randomUUID ();
        promotionSpace.setSpaceKey (uuid.toString ());
        promotionSpace.setCreateTime (new Date ());
        promotionSpace.setUpdateTime (new Date ());
        promotionSpace.setIsDel (0);

        promotionSpaceMapper.savePromotionSpace (promotionSpace);
    }

    /*根据id查询广告位*/
    public PromotionSpace findPromotionByID(int id) {

        PromotionSpace promotionByID = promotionSpaceMapper.findPromotionByID (id);

        return promotionByID;
    }

    /*修改广告位*/
    @Override
    public void updatePromotionSpace(PromotionSpace promotionSpace) {


        //封装信息
        promotionSpace.setUpdateTime (new Date ());

        promotionSpaceMapper.updatePromotionSpace (promotionSpace);
    }

}
